//
//  HomeMessage.m
//  uteped_sdk
//
//  Created by mateng on 2024/2/20.
//

#import "HomeMessage.h"
#import "DataSyncHelper.h"

#define PATH                      @"home"

@implementation HomeMessage

- (NSString *)getPath {
    return PATH;
}

- (BOOL)methodCallConsumed:(NSString *)method params:(NSDictionary *)params result:(FlutterResult)result {
    BOOL consumed = YES;
    if ([super methodCallConsumed:method params:params result:result])
        return YES;
    
    assert(method != nil);
    
    if ([method isEqualToString: M_syncWorkoutHistoryData]) {
        if (![self isConnected]) {
            result(@NO);
            return YES;
        }
        
        NSDictionary *map = [params objectForKey:TYPE_MAP];
        NSInteger st = [[map objectForKey:@"startTime"] intValue];
        NSInteger et = [[map objectForKey:@"endTime"] intValue];
        [[DataSyncHelper shareInstance] fetchWorkoutData:st endTime:et];
        result(@(YES));
    } else if ([method isEqualToString: M_getMotionSummaryData]) {
        if (![self isConnected]) {
            result(@NO);
            return YES;
        }
        
        NSDictionary *map = [params objectForKey:TYPE_MAP];
        NSInteger st = [[map objectForKey:@"startTime"] intValue];
        NSInteger et = [[map objectForKey:@"endTime"] intValue];
        [[DataSyncHelper shareInstance] fetchFitnessData:0 endTime:0];
        result(@(YES));
    } else {
        consumed = NO;
    }
    
    return consumed;
}

@end
